<template>
  <div class="userList h100">
    <edit-page-new
      @goBackPage="goBackPage"
      :rightBtnArr="rightBtnArr"
      :showTopTitle="showTopTitle"
      :showBackBtn="true"
    >
      <div class="tableList">
        <list-table-new v-bind="tableConfig" ref="userTable"></list-table-new>
      </div>
    </edit-page-new>
    <dialogPublic
      title="信息选择"
      :show.sync="showUser"
      @doSubmit="newMemberSelect"
      @doClose="() => (showUser = false)"
      :fullscreen="true"
      appendTobody
    >
      <newMemberSelect
        ref="newMember"
        v-if="showUser"
        :seleteSetting="orgMemberSelect"
      ></newMemberSelect>
    </dialogPublic>
  </div>
</template>
<script>
import {
  postUserList,
  postUserAdd,
  postUserDelete,
} from "@/api/systemManagement/postConfig.js";
import newMemberSelect from "../../../../components/memberSelect/newMemberSelect.vue";
export default {
  components: {
    newMemberSelect,
  },
  props: {
    currentRowData: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      orgMemberSelect: {
        chosedData: [],
        defaultOrg: "",
        level: null,
        multiple: true,
        type: "user-select",
        backData: false,
        allowSameUser:true,
      },
      showUser: false,
      showTopTitle: false,
      rightBtnArr: [],
      tableConfig: {
        showAllSearch: false,
        showIndex: true,
        selectionShow: false,
        showFilterBtn: false,
        showCustomBtn: false,
        searchObj: {
          searchMethod: (params, that) => {
            if (this.tableConfig.searchObj) {
              this.getTableData(params);
            } else {
            }
          },
          searchArr: [
            {
              type: "input",
              label: "组织名称",
              model: "orgName",
              placeholder: "请输入",
            },
            {
              type: "input",
              label: "用户名",
              model: "userName",
              placeholder: "请输入",
            },
            {
              type: "input",
              label: "用户账号",
              model: "userAccount",
              placeholder: "请输入",
            },
          ],
          queryData: {
            page: 1,
            pageSize: 15,
          },
        },
        tableMethods: {
          rowClick: (e) => {},
        },
        actionList: [
          {
            name: "添加用户",
            icon: "el-icon-plus",
            method: () => {
              this.addUser();
            },
          },
        ],
        column: [
          {
            label: "组织名称",
            prop: "orgName",
          },
          {
            label: "岗位名称",
            prop: "postName",
          },
          {
            label: "用户账号",
            prop: "userAccount",
          },
          {
            label: "用户名",
            prop: "userName",
          },
          {
            label: "添加时间",
            prop: "createTime",
          },
          {
            label: "操作",
            type: "button",
            buttonArr: [
              {
                text: "删除",
                isShow: () => {
                  return true;
                },
                methods: (row, index) => {
                  this.deleteUser(row.id);
                },
              },
            ],
          },
        ],
        tableData: [],
        paginationObj: {
          pageSizes: [15, 30, 50, 100],
        },
        totalNumber: 0,
      },
    };
  },
  created() {},
  mounted() {
    this.getTableData();
  },
  watch: {},
  methods: {
    newMemberSelect() {
      let backData = this.$refs.newMember.getSelectData()
      let param = [];
      if (backData.legth != 0) {
        backData.map((item) => {
          let paramObj = {};
          paramObj.postId = this.currentRowData.id;
          paramObj.userAccount = item.account;
          paramObj.userOrg = item.orgId
          param.push(paramObj);
        });
      }
      postUserAdd(param).then(
        (res) => {
          if (res.code == 200) {
            this.showUser = false;
            this.getTableData();
            this.$message.success(res.description);
          }
        },
        (err) => {
          this.$message.error(err);
        }
      );
    },
    //新增当前数据
    addUser() {
      this.showUser = true;
      this.$nextTick(() =>{
        this.$refs.newMember.chosedData = []
       
      })
      
    },
    //删除当前数据
    deleteUser(id) {
      this.$confirm("确定要删除选中数据吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postUserDelete({ id: id }).then(
            (res) => {
              if (res.code == 200) {
                this.$message.success(res.description);
                this.getTableData();
              }
            },
            (err) => {
              this.$message.error(err);
            }
          );
        })
        .catch((e) => {});
    },
    //获取表格数据
    getTableData(params) {
      if (params) {
        this.$set(this.tableConfig.searchObj, "queryData", params);
      }
      let queryData = Object.assign({}, this.tableConfig.searchObj.queryData);
      queryData.postId = this.currentRowData.id;
      postUserList(queryData).then(
        (res) => {
          if (res.code == 200) {
            this.$set(this.tableConfig, "tableData", res.data.list);
            this.$set(this.tableConfig, "totalNumber", res.data.total);
          }
        },
        (error) => {
          this.$message.error(error);
        }
      );
    },
    goBackPage() {
      this.$emit("goBackPage");
    },
  },
};
</script>
<style lang="less" scoped>
.userList {
  /deep/.editPage .edit-page-btn {
    height: 48px;
  }
  /deep/.paddingSize {
    padding: 0 20px;
  }
  /deep/.list-table-main .el-table {
    height: 490px !important;
  }
}
</style>